﻿--[[
    SpamBayes for WoW, a lightweight bayesian antispam for World of Warcraft
    Copyright @ 2010 Arnaud Dovi (Merah@AthelLoren, ad@heapoverflow.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]

--[[
$Rev:: 41                    $:  Revision of last commit
$Author:: arnaud             $:  Author of last commit
$Date:: 2012-09-02 21:53:50 #$:  Date of last commit
$WoW:: 5.0.5.16030           $:  Client of the last tests
]]

----------------- GLOBALS ----------------
SpamBayes                             = {}
SpamBayes.xml                         = {}
------------------------------------------

local MAJOR_VERSION                   = "50001"
local MINOR_VERSION                   = tonumber(("$Rev: 41 $"):match("%d+"))
SpamBayes.MINOR_VERSION               = SpamBayes.MINOR_VERSION == nil and MINOR_VERSION or (MINOR_VERSION > SpamBayes.MINOR_VERSION and MINOR_VERSION or SpamBayes.MINOR_VERSION)

local function initFrames(db)
    local sb             = SpamBayes, lastValue
    local global         = "SpamBayes"
    local globalFrame    = CreateFrame("Frame", global.."Frame", UIParent) -- local
    local headerFrame    = CreateFrame("Frame", global.."Header", globalFrame)
    local logFrame       = CreateFrame("Frame", global.."Log", globalFrame)
    local logScrollFrame = CreateFrame("ScrollingMessageFrame", global.."LogScroll", logFrame)
    local logSlider      = CreateFrame("Slider", global.."LogSlider", logFrame)
    local infoFrame      = CreateFrame("Frame", global.."Info", globalFrame)
    local infoText      = infoFrame:CreateFontString(nil, nil, "Tooltip_Med")
    local footerFrame    = CreateFrame("Frame", global.."Footer", globalFrame)
    local gripButton     = CreateFrame("Button", global.."Grip", logFrame)
    local logoButton     = CreateFrame("Button", global.."Logo", headerFrame)
    local headerText     = headerFrame:CreateFontString(nil, nil, "SystemFont_Shadow_Outline_Huge2")
    local aboutButton    = CreateFrame("Button", global.."AboutButton", footerFrame, "UIMenuButtonStretchTemplate")
    local helpButton     = CreateFrame("Button", global.."HelpButton", footerFrame, "UIMenuButtonStretchTemplate")
    local optionButton   = CreateFrame("Button", global.."OptionButton", footerFrame, "UIMenuButtonStretchTemplate")
    local clearButton    = CreateFrame("Button", global.."ClearButton", footerFrame, "UIMenuButtonStretchTemplate")
    local aboutFrame     = CreateFrame("Frame", global.."AboutFrame", UIParent)
    local aboutText1     = aboutFrame:CreateFontString(nil, nil, "SystemFont_OutlineThick_WTF")
    local aboutText2     = aboutFrame:CreateFontString(nil, nil, "NumberFont_Outline_Large")
    local aboutText3     = aboutFrame:CreateFontString(nil, nil, "NumberFontNormalHuge")
    local aboutText4     = aboutFrame:CreateFontString(nil, nil, "Tooltip_Med")
    local helpFrame      = CreateFrame("Frame", global.."HelpFrame", UIParent)
    local helpText       = CreateFrame("ScrollingMessageFrame", global.."HelpText", helpFrame)
    local optionFrame    = CreateFrame("Frame", global.."OptionFrame", UIParent)
    local checkButton1   = CreateFrame("CheckButton", global.."CheckButton1", optionFrame, "OptionsSmallCheckButtonTemplate")
    local checkButton1s  = checkButton1:CreateFontString("SpamBayesFontString", "ARTWORK", "GameFontNormal")
    local checkButton2   = CreateFrame("CheckButton", global.."CheckButton2", optionFrame, "OptionsSmallCheckButtonTemplate")
    local checkButton2s  = checkButton2:CreateFontString("SpamBayesFontString", "ARTWORK", "GameFontNormal")
    local checkButton3   = CreateFrame("CheckButton", global.."CheckButton3", optionFrame, "OptionsSmallCheckButtonTemplate")
    local checkButton3s  = checkButton3:CreateFontString("SpamBayesFontString", "ARTWORK", "GameFontNormal")
    local checkButton4   = CreateFrame("CheckButton", global.."CheckButton4", optionFrame, "OptionsSmallCheckButtonTemplate")
    local checkButton4s  = checkButton4:CreateFontString("SpamBayesFontString", "ARTWORK", "GameFontNormal")
    local closeButton1   = CreateFrame("Button", global.."CloseButton1", headerFrame)
    local closeButton2   = CreateFrame("Button", global.."CloseButton2", aboutFrame)
    local closeButton3   = CreateFrame("Button", global.."CloseButton3", helpFrame)
    local closeButton4   = CreateFrame("Button", global.."CloseButton4", optionFrame)
    local function D(text)
        print("|c80808080[SpamBayes]: "..text.."|r")
    end
    local globalBackdrop = {
        bgFile   = "Interface\\ChatFrame\\ChatFrameBackground",
        edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
        tile     = false, tileSize = 16, edgeSize = 16,
        insets   = { left = 5, right = 5, top = 5, bottom = 5 }
    }
    local sliderBackdrop = {
        bgFile   = "Interface\\Buttons\\UI-SliderBar-Background",
        edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
        tile     = true, tileSize = 8, edgeSize = 8,
        insets   = { left = 3, right = 3, top = 6, bottom = 6 }
    }
    local function closeFrame(this)
        local name = this:GetName()
        if name == global.."CloseButton1" then
            aboutFrame:Hide()
            helpFrame:Hide()
            optionFrame:Hide()
            return this:GetParent():GetParent():Hide()
        end
        return this:GetParent():Hide()
    end
    local function toggleAbout()
        if not globalFrame:IsVisible() then
            globalFrame:Show()
        end
        if optionFrame:IsVisible() then
            optionFrame:Hide()
        end
        if helpFrame:IsVisible() then
            helpFrame:Hide()
        end
        if aboutFrame:IsVisible() then aboutFrame:Hide() return end
        aboutFrame:Show()
    end
    local function toggleHelp()
        if not globalFrame:IsVisible() then
            globalFrame:Show()
        end
        if aboutFrame:IsVisible() then
            aboutFrame:Hide()
        end
        if optionFrame:IsVisible() then
            optionFrame:Hide()
        end
        if helpFrame:IsVisible() then helpFrame:Hide() return end
        helpFrame:Show()
    end
    local function toggleOption()
        if not globalFrame:IsVisible() then
            globalFrame:Show()
        end
        if aboutFrame:IsVisible() then
            aboutFrame:Hide()
        end
        if helpFrame:IsVisible() then
            helpFrame:Hide()
        end
        if optionFrame:IsVisible() then optionFrame:Hide() return end
        optionFrame:Show()
    end
    local function UpdateButtonIsAddOnEnabled()
        local pressed = checkButton1:GetChecked()
        db["isAddOnEnabled"] = pressed == 1 and true or false
        D(sb.isAddOnEnabled() and "ON" or "OFF")
        sb.shutdown(false)
    end
    local function UpdateButtonLinksEnabled()
        local pressed = checkButton2:GetChecked()
        db["linksEnabled"] = pressed == 1 and true or false
        D(sb.linksEnabled() and "CC Links ON" or "CC Links OFF")
    end
    local function UpdateButtonReportsEnabled()
        local pressed = checkButton3:GetChecked()
        db["autoreportEnabled"] = pressed == 1 and true or false
        D(sb.rpEnabled() and "Auto reports ON" or "Auto reports OFF")
    end
    local function UpdateButtonHiderpEnabled()
        local pressed = checkButton4:GetChecked()
        db["hiderpEnabled"] = pressed == 1 and true or false
        D(sb.HiderpEnabled() and "Hide report notification ON" or "Hide report notification OFF")
    end
    local function onClick(self, link, text, button)
        if button == "RightButton" and string.match(link, "player:") or (sb.linksEnabled() and button == "LeftButton" and not string.match(link, "player:")) then
            ChatFrame_OnHyperlinkShow(self, link, text, button)
        end
    end
    local function wheelSlide(self, delta)
        if delta == 1 then
            logScrollFrame:ScrollUp()
        else
            logScrollFrame:ScrollDown()
        end
    end
    local function onUpdateSlider(self, value)
        if lastValue and value == lastValue then return end -- used to stop an uncontrolable flood
        lastValue = value
        local min, max = logSlider:GetMinMaxValues()
        logScrollFrame:SetScrollOffset(max - value)
    end
    local function onToggleSlider()
        if not logScrollFrame:IsVisible() then return end
        local totalmsg     = logScrollFrame:GetNumMessages()
        local displayedmsg = logScrollFrame:GetNumLinesDisplayed()
        local scrollSize   = totalmsg - displayedmsg
        local scrollValue  = scrollSize - logScrollFrame:GetCurrentScroll() -- for a slider from bottom to top
        if totalmsg > displayedmsg then
            logSlider:SetMinMaxValues(0, scrollSize)
            logSlider:SetValue(scrollValue)
            if not logSlider:IsVisible() then logSlider:Show() end
        else -- no slider needed
            logSlider:Hide()
        end
    end
    local function clearLog()
        logScrollFrame:Clear()
        onToggleSlider()
    end
    globalFrame:EnableMouse(true)
    globalFrame:SetMovable(true)
    globalFrame:SetResizable(true)
    globalFrame:SetUserPlaced(true)
    globalFrame:SetClampedToScreen(true)
    globalFrame:SetScript("OnMouseDown", function() globalFrame:StartMoving() end)
    globalFrame:SetScript("OnMouseUp", function() globalFrame:StopMovingOrSizing() end)
    globalFrame:SetHeight(500)
    globalFrame:SetWidth(1024)
    globalFrame:SetPoint("CENTER")
    globalFrame:SetMinResize(365, 255)
    globalFrame:SetFrameLevel(50)
    globalFrame:SetFrameStrata("DIALOG")
    globalFrame:SetScript("OnShow", onToggleSlider)
    headerFrame:SetHeight(50)
    headerFrame:SetPoint("TOPLEFT")
    headerFrame:SetPoint("TOPRIGHT")
    headerFrame:SetBackdrop(globalBackdrop)
    headerFrame:SetBackdropColor(128/255, 128/255, 128/255)
    headerFrame:SetFrameLevel(9)
    footerFrame:SetHeight(50)
    footerFrame:SetPoint("BOTTOMLEFT")
    footerFrame:SetPoint("BOTTOMRIGHT")
    footerFrame:SetBackdrop(globalBackdrop)
    footerFrame:SetBackdropColor(128/255, 128/255, 128/255)
    footerFrame:SetFrameLevel(15)
    infoFrame:SetHeight(80)
    infoFrame:SetPoint("BOTTOMLEFT", footerFrame, "TOPLEFT", 0, -1)
    infoFrame:SetPoint("BOTTOMRIGHT", footerFrame, "TOPRIGHT", 0, -1)
    infoFrame:SetBackdrop(globalBackdrop)
    infoFrame:SetBackdropColor(0, 0, 0, 0.8)
    infoFrame:SetFrameLevel(15)
    infoText:SetTextColor(120/255, 120/255, 120/255, 1)
    infoText:SetPoint("TOPLEFT", 8, -8)
    infoText:SetWidth(600)
    infoText:SetJustifyH("left")
    infoText:SetText(string.format("Total messages trained: %d Spam, %d Ham\nMessages classified: %d Spam, %d Ham, %d Unsure\nLast report : %s %s", SPAMBAYESDB.classifierdb.nspam or 0, SPAMBAYESDB.classifierdb.nham or 0, SPAMBAYESDB.classifierdb.cspam or 0, SPAMBAYESDB.classifierdb.cham or 0, SPAMBAYESDB.classifierdb.cunsure or 0, sb.lastrp or "-", ((sb.rpEnabled() and SPAMBAYESDB.classifierdb.nspam >= 10 and SPAMBAYESDB.classifierdb.nham >= 10) or not sb.rpEnabled()) and "" or "(you must train at least 15 spams and 30 hams to enable auto reports)"))
    logoButton:SetNormalTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_logo")
    logoButton:SetPoint("CENTER", headerFrame, "CENTER", -150, 0)
    logoButton:SetWidth(32)
    logoButton:SetHeight(32)
    logoButton:SetFrameLevel(10)
    headerText:SetText("SpamBayes Control Center")
    headerText:SetTextColor(1, 1, 1, 0.95)
    headerText:SetPoint("BOTTOMLEFT", logoButton, "BOTTOMRIGHT", 2, 5)
    logFrame:SetPoint("TOPLEFT", headerFrame, "BOTTOMLEFT", 0, 1)
    logFrame:SetPoint("TOPRIGHT", headerFrame, "BOTTOMRIGHT", 0, 1)
    logFrame:SetPoint("BOTTOMRIGHT", infoFrame, "TOPRIGHT", 0, -1)
    logFrame:SetPoint("BOTTOMLEFT", infoFrame, "TOPLEFT", 0, -1)
    logFrame:SetBackdrop(globalBackdrop)
    logFrame:SetBackdropColor(0, 0, 0, 0.8)
    logFrame:SetFrameLevel(15)
    logScrollFrame:SetPoint("TOPLEFT", 8, -8)
    logScrollFrame:SetPoint("TOPRIGHT", -34, -8)
    logScrollFrame:SetPoint("BOTTOMLEFT", 8, 8)
    logScrollFrame:SetPoint("BOTTOMRIGHT", -34, 8)
    logScrollFrame:SetFrameLevel(60)
    logScrollFrame:SetFontObject("AchievementFont_Small")
    logScrollFrame:SetTextColor(1, 1, 1, 1)
    logScrollFrame:SetJustifyH("LEFT")
    logScrollFrame:SetJustifyV("BOTTOM")
    logScrollFrame:SetFading(false)
    logScrollFrame:SetScript("OnHyperlinkClick", onClick)
    logScrollFrame:SetScript("OnSizeChanged", onToggleSlider)
    logScrollFrame:SetScript("OnMessageScrollChanged", onToggleSlider)
    logScrollFrame:SetMaxLines(10000)
    logScrollFrame:SetHyperlinksEnabled(true)
    logScrollFrame:SetScript("OnMouseWheel", wheelSlide)
    logSlider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Vertical")
    logSlider:SetPoint("TOPLEFT", logScrollFrame, "TOPRIGHT", 10, 0)
    logSlider:SetPoint("BOTTOMLEFT", logScrollFrame, "BOTTOMRIGHT", 10, 10)
    logSlider:SetOrientation("VERTICAL")
    logSlider:SetBackdrop(sliderBackdrop)
    logSlider:SetWidth(16)
    logSlider:SetValueStep(1)
    logSlider:SetScript("OnValueChanged", onUpdateSlider)
    logSlider:SetFrameLevel(60)
    gripButton:SetNormalTexture("Interface\\AddOns\\SpamBayes\\textures\\grip")
    gripButton:SetHighlightTexture("Interface\\AddOns\\SpamBayes\\textures\\grip")
    gripButton:SetWidth(16)
    gripButton:SetHeight(16)
    gripButton:SetScript("OnMouseDown", function() globalFrame:StartSizing() end)
    gripButton:SetScript("OnMouseUp", function() globalFrame:SetScript("OnSizeChanged", nil) globalFrame:StopMovingOrSizing() --[[updateScroll()]] end)
    gripButton:SetPoint("BOTTOMRIGHT", -2, 2)
    gripButton:SetFrameLevel(60)
    aboutButton:SetText("|cB4B4B4B4About|r")
    aboutButton:SetPoint("BOTTOMRIGHT", -10, 14)
    aboutButton:SetFrameLevel(55)
    aboutButton:SetHeight(22)
    aboutButton:SetWidth(44)
    aboutButton:SetScript("OnClick", toggleAbout)
    helpButton:SetText("|cB4B4B4B4Help|r")
    helpButton:SetPoint("BOTTOMRIGHT", aboutButton, "BOTTOMLEFT", -10, 0)
    helpButton:SetFrameLevel(55)
    helpButton:SetHeight(22)
    helpButton:SetWidth(40)
    helpButton:SetScript("OnClick", toggleHelp)
    optionButton:SetText("|cB4B4B4B4Options|r")
    optionButton:SetPoint("BOTTOMRIGHT", helpButton, "BOTTOMLEFT", -10, 0)
    optionButton:SetFrameLevel(55)
    optionButton:SetHeight(22)
    optionButton:SetWidth(54)
    optionButton:SetScript("OnClick", toggleOption)
    clearButton:SetText("|cB4B4B4B4Clear|r")
    clearButton:SetPoint("BOTTOMRIGHT", optionButton, "BOTTOMLEFT", -10, 0)
    clearButton:SetFrameLevel(55)
    clearButton:SetHeight(22)
    clearButton:SetWidth(44)
    clearButton:SetScript("OnClick", clearLog)
    aboutFrame:SetWidth(1024)
    aboutFrame:SetHeight(260)
    aboutFrame:SetPoint("TOPLEFT", footerFrame, "BOTTOMLEFT", 0, -5)
    aboutFrame:SetPoint("TOPRIGHT", footerFrame, "BOTTOMRIGHT", 0, -5)
    aboutFrame:SetBackdrop(globalBackdrop)
    aboutFrame:SetBackdropColor(12/255, 21/255, 50/255)
    aboutFrame:SetFrameLevel(15)
    aboutFrame:SetClampedToScreen(true)
    aboutFrame:SetFrameStrata("DIALOG")
    aboutText1:SetText("SpamBayes for World of Warcraft")
    aboutText1:SetTextColor(1, 1, 1, 1)
    aboutText1:SetPoint("CENTER", 0, 80)
    aboutText2:SetText("v"..MAJOR_VERSION.." build |cff00ff00"..tostring(sb.MINOR_VERSION).."|r")
    aboutText2:SetTextColor(1, 1, 1, 1)
    aboutText2:SetPoint("BOTTOMLEFT", aboutText1, "BOTTOMRIGHT", 0, 4)
    aboutText3:SetText("|cffc023ffby |cff69ccf0Merax|cffc023ff, |cffabd473Merah|cffc023ff, |cffffffffMera|cffc023ff @ La Croisade Écarlate FR|r")
    aboutText3:SetPoint("CENTER", 0, 30)
    aboutText4:SetText("- uses an algorithm of probabilities converted from SpamBayes Python a spam filter developed since 2002\nwhich is a combination of work from Gary Robinson and Tim Peters and many contributers\nsee http://spambayes.sourceforge.net/background.html.\n\n(An integration of SpamBayes into Thunderbird3 exist, look for the plugin ThunderBayes++ I am maintaining for TB3)")
    aboutText4:SetPoint("CENTER", 0, -50)
    helpFrame:SetWidth(1100)
    helpFrame:SetHeight(200)
    helpFrame:SetPoint("TOPLEFT", footerFrame, "BOTTOMLEFT", 0, -5)
    helpFrame:SetPoint("TOPRIGHT", footerFrame, "BOTTOMRIGHT", 0, -5)
    helpFrame:SetBackdrop(globalBackdrop)
    helpFrame:SetBackdropColor(40/255, 46/255, 2/255)
    helpFrame:SetFrameLevel(15)
    helpFrame:SetFrameStrata("DIALOG")
    helpFrame:SetClampedToScreen(true)
    helpText:SetPoint("TOPLEFT", 8, -10)
    helpText:SetPoint("TOPRIGHT", -10, -10)
    helpText:SetPoint("BOTTOMLEFT", 8, 10)
    helpText:SetPoint("BOTTOMRIGHT", -10, 10)
    helpText:SetFontObject("Tooltip_Med")
    helpText:SetJustifyV("TOP")
    helpText:SetJustifyH("CENTER")
    helpText:SetInsertMode("top")
    helpText:SetMaxLines(10)
    helpText:SetFading(false)
    helpText:AddMessage("|cff989afc- BUGS & SUGGESTIONS: must be sent to Curseforge ticket, if the report already exists vote and comment inside, if not, create a new ticket. Any bug or suggestion made outside this rule will not be considered.")
    helpText:AddMessage("|cff89bd6f- Auto reports are disabled by default. Please note you will need to train at least 10 ham and spam to use, this is a wanted restriction to lower false reports of a newly created database.")
    helpText:AddMessage("|cff989afc- The settings and the spam database are global to all characters and are stored in the folder WTF\\Account\\<username>\\SavedVariables\\SpamBayes.lua")
    helpText:AddMessage("|cff89bd6f- The more you will train unique spams and hams and the more autonomous it will be and the more correct classification will be.")
    helpText:AddMessage("|cff89bd6f- Unlike most antispams, SpamBayes is very intelligent, it does not uses hardcoded string patterns of known spammers, you are not forced to download X update of the AddOn to stop Y spammer, but instead, it uses a powerful algorithm designed by a vaste community of geeks to calculate the weight of a phrase as a probability so by training X and Y message, you will be able to stop A, B, C messages.")
    helpText:AddMessage("|cff989afc- Messages displayed in Red = Spam, Green = Ham, and Blank = Unsure. Unlike most antispams, SpamBayes never totally hides a spam, it displays everything in the control center and the chat windows except spams (by default, messages higher than 90% probability).")
    helpText:AddMessage("|cff89bd6f- It is better to keep a balanced number of messages learned or a number of ham slightly higher in preferring to teach him phrases containing the most words and hams identified greater than 50%.")
    helpText:AddMessage("|cff989afc- Learning a chat message as ham or spam is done by right-clicking the playername in the chatwindow or this control center.")
    helpText:AddMessage("|cff89bd6f- By default, the database is blank, all messages received are classified Unsure, you will have to teach to distinguish spam from a ham.\n(support for an \"official\" and ready-to-use database is possible, see the suggestion line and follow the instructions).")
    optionFrame:SetWidth(300)
    optionFrame:SetHeight(200)
    optionFrame:SetPoint("TOPRIGHT", footerFrame, "BOTTOMRIGHT", 0, -5)
    optionFrame:SetBackdrop(globalBackdrop)
    optionFrame:SetBackdropColor(5/255, 39/255, 1/255)
    optionFrame:SetFrameLevel(15)
    optionFrame:SetFrameStrata("DIALOG")
    optionFrame:SetClampedToScreen(true)
    checkButton1:SetPoint("TOPLEFT", 5, -5)
    checkButton1:SetFrameLevel(18)
    checkButton1:SetID(1)
    checkButton1:SetScript("OnClick", UpdateButtonIsAddOnEnabled)
    checkButton1:SetChecked(sb.isAddOnEnabled() and true or false)
    checkButton1s:SetSize(130,20)
    checkButton1s:SetText("Enable SpamBayes")
    checkButton1s:SetPoint("BOTTOMLEFT", checkButton1, "BOTTOMRIGHT", 0, 4)
    checkButton1s:SetJustifyH("left")
    checkButton2:SetPoint("TOPLEFT", 5, -25)
    checkButton2:SetFrameLevel(18)
    checkButton2:SetID(2)
    checkButton2:SetScript("OnClick", UpdateButtonLinksEnabled)
    checkButton2:SetChecked(sb.linksEnabled() and true or false)
    checkButton2s:SetSize(130,20)
    checkButton2s:SetText("Enable links in CC")
    checkButton2s:SetPoint("BOTTOMLEFT", checkButton2, "BOTTOMRIGHT", 0, 4)
    checkButton2s:SetJustifyH("left")
    checkButton3:SetPoint("TOPLEFT", 5, -45)
    checkButton3:SetFrameLevel(18)
    checkButton3:SetID(3)
    checkButton3:SetScript("OnClick", UpdateButtonReportsEnabled)
    checkButton3:SetChecked(sb.rpEnabled() and true or false)
    checkButton3s:SetSize(130,20)
    checkButton3s:SetText("Enable auto reports")
    checkButton3s:SetPoint("BOTTOMLEFT", checkButton3, "BOTTOMRIGHT", 0, 4)
    checkButton3s:SetJustifyH("left")
    checkButton4:SetPoint("TOPLEFT", 5, -65)
    checkButton4:SetFrameLevel(18)
    checkButton4:SetID(4)
    checkButton4:SetScript("OnClick", UpdateButtonHiderpEnabled)
    checkButton4:SetChecked(sb.HiderpEnabled() and true or false)
    checkButton4s:SetSize(150,20)
    checkButton4s:SetText("Hide report notification")
    checkButton4s:SetPoint("BOTTOMLEFT", checkButton4, "BOTTOMRIGHT", 0, 4)
    checkButton4s:SetJustifyH("left")
    closeButton1:SetNormalTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton1:SetHighlightTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton1:GetNormalTexture():SetTexCoord(0, 0.5, 0, 1);
    closeButton1:GetHighlightTexture():SetTexCoord(0.5, 1, 0, 1);
    closeButton1:SetHeight(16)
    closeButton1:SetWidth(16)
    closeButton1:SetPoint("TOPRIGHT", -8, -8)
    closeButton1:SetFrameLevel(60)
    closeButton1:SetID(2)
    closeButton1:SetScript("OnClick", closeFrame)
    closeButton2:SetNormalTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton2:SetHighlightTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton2:GetNormalTexture():SetTexCoord(0, 0.5, 0, 1);
    closeButton2:GetHighlightTexture():SetTexCoord(0.5, 1, 0, 1);
    closeButton2:SetHeight(16)
    closeButton2:SetWidth(16)
    closeButton2:SetPoint("TOPRIGHT", -8, -8)
    closeButton2:SetFrameLevel(60)
    closeButton2:SetID(3)
    closeButton2:SetScript("OnClick", closeFrame)
    closeButton3:SetNormalTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton3:SetHighlightTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton3:GetNormalTexture():SetTexCoord(0, 0.5, 0, 1);
    closeButton3:GetHighlightTexture():SetTexCoord(0.5, 1, 0, 1);
    closeButton3:SetHeight(16)
    closeButton3:SetWidth(16)
    closeButton3:SetPoint("TOPRIGHT", -8, -8)
    closeButton3:SetFrameLevel(60)
    closeButton3:SetID(4)
    closeButton3:SetScript("OnClick", closeFrame)
    closeButton4:SetNormalTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton4:SetHighlightTexture("Interface\\AddOns\\SpamBayes\\textures\\spambayes_tint_close")
    closeButton4:GetNormalTexture():SetTexCoord(0, 0.5, 0, 1);
    closeButton4:GetHighlightTexture():SetTexCoord(0.5, 1, 0, 1);
    closeButton4:SetHeight(16)
    closeButton4:SetWidth(16)
    closeButton4:SetPoint("TOPRIGHT", -8, -8)
    closeButton4:SetFrameLevel(60)
    closeButton4:SetID(5)
    closeButton4:SetScript("OnClick", closeFrame)
    optionFrame:Hide()
    aboutFrame:Hide()
    helpFrame:Hide()
    globalFrame:Hide()
    logSlider:Hide()
    sb.xml.frame    = globalFrame
    sb.xml.oframe   = optionFrame
    sb.xml.hframe   = helpFrame
    sb.xml.aframe   = aboutFrame
    sb.xml.log      = logScrollFrame
    sb.xml.setinfo  = infoText
    sb.xml.check    = checkButton1
end

SpamBayes.xml.init  = initFrames

